//priority 10000
const CustomMachineContainer = Java.loadClass("fr.frinn.custommachinery.common.init.CustomMachineContainer")

PlayerEvents.inventoryOpened(event => {
    if (event.inventoryContainer instanceof CustomMachineContainer) {
        /**@type Internal.BlockEntity*/
        var Tile = event.inventoryContainer.getTile()
        event.player.sendData("CustomMachineContainerOpen", { 'type': event.player.level.getBlock(Tile.blockPos).id, 'pos': { x: Tile.blockPos.x, y: Tile.blockPos.y, z: Tile.blockPos.z } })
    }
})

PlayerEvents.inventoryClosed(event => {
    if (event.inventoryContainer instanceof CustomMachineContainer) {
        event.player.sendData("CustomMachineContainerClose", {})
    }
})

NetworkEvents.dataReceived("getCustomMachineState", event => {
    var stateName = event.data.getString("stateName")
    var pos = event.data.get("blockpos")
    var block = event.player.level.getBlock(pos.x, pos.y, pos.z)
    /**@type Internal.MachineTile*/
    var blockEntity = block.getEntity()
    var Machine = CustomMachine.of(block)
    var IProcessor = blockEntity.getProcessor()
})
